import ajax from '@/utils/request'
import { concatUrl } from '@/utils'

// 获取购物车列表
export function getCartList(data = {}, fields: string | object = { fields: '*' }) {
    return ajax({
        url: concatUrl('/v1/cart/index', fields),
        data
    })
}

// 更新购物车商品数量
export function updateNumber(data, fields: string | object = { fields: '*' }) {
    return ajax({
        url: concatUrl('/v1/cart/update-item-number', fields),
        data,
        method: 'POST'
    })
}

// 获取购物车选中商品价格
export function getPrice(data = {}, fields: string | object = { fields: 'totalPrice' }) {
    return ajax({
        url: concatUrl('/v1/cart/get-selected-price', fields),
        data
    })
}

// 删除购物车商品
export function deleteCart(data) {
    return ajax({
        url: concatUrl('/v1/cart/delete', data),
        method: 'DELETE'
    })
}

// 获取选中的购物车物品
export function getSelectedItem(data) {
    return ajax({
        url: concatUrl('/v1/cart/get-selected-item', data),
        method: 'GET'
    })
}
